package com.ly.heart.service.impl;

import com.ly.common.exception.CustomException;
import com.ly.common.utils.DateUtils;
import com.ly.common.utils.SecurityUtils;
import com.ly.common.utils.StringUtils;
import com.ly.common.utils.erp.SnowflakeIdWorker;
import com.ly.heart.domain.KingFinanceReceiptDetailEntity;
import com.ly.heart.mapper.KingFinanceReceiptDetailMapper;
import com.ly.heart.service.IKingFinanceReceiptDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 财务模块-收款明细列表 服务实现类
 * </p>
 *
 * @author WuZH
 * @since 2024-08-04
 */
@Service
public class KingFinanceReceiptDetailServiceImpl extends ServiceImpl<KingFinanceReceiptDetailMapper, KingFinanceReceiptDetailEntity> implements IKingFinanceReceiptDetailService {

    @Resource
    private KingFinanceReceiptDetailMapper kingFinanceReceiptDetailMapper;

    @Override
    public KingFinanceReceiptDetailEntity saveSingle ( KingFinanceReceiptDetailEntity kingFinanceReceiptDetailEntity ) {
        kingFinanceReceiptDetailEntity.setId ( SnowflakeIdWorker.getInstance ().nextStringId () );
        kingFinanceReceiptDetailEntity.setCreateTime ( DateUtils.getNowDate () );
        kingFinanceReceiptDetailEntity.setCreateBy ( StringUtils.isNoneBlank ( kingFinanceReceiptDetailEntity.getCreateBy () ) ? kingFinanceReceiptDetailEntity.getCreateBy () : SecurityUtils.getLoginUser ().getUser ().getUserId () );
        boolean save = this.save ( kingFinanceReceiptDetailEntity );
        if ( !save ) {
            throw new CustomException ( "新增收款单明细" );
        }
        return kingFinanceReceiptDetailEntity;
    }

    @Override
    public List<KingFinanceReceiptDetailEntity> queryList ( KingFinanceReceiptDetailEntity kingFinanceReceiptDetailEntity ) {
        List<KingFinanceReceiptDetailEntity> kingFinanceReceiptDetailEntities = kingFinanceReceiptDetailMapper.queryList ( kingFinanceReceiptDetailEntity );
        return kingFinanceReceiptDetailEntities;
    }
}
